#include "bookmarklist.h"

BookmarkList::BookmarkList()
{
}
BookmarkList::~BookmarkList()
{
    while(!this->isEmpty())
    {
	Bookmark* b = (Bookmark*)this->takeFirst();
	delete b;
    }
}
void BookmarkList::clearList()
{
    while(!this->isEmpty())
    {
	Bookmark* b = (Bookmark*)this->takeFirst();
	delete b;
    }
}
bool BookmarkList::serialize(QXmlStreamWriter * w)
{
    int count = this->count();
    w->setAutoFormatting(true);
    w->writeStartDocument();
    w->writeStartElement("BookmarkList");
    for(int i=0;i<count;i++)
    {
	Bookmark* bm = (Bookmark*)this->at(i);
	bm->serialize(w);
    }
    w->writeEndElement();
    w->writeEndDocument();
    return true;
}
bool BookmarkList::deserialize(QXmlStreamReader * r)
{
    while(!r->atEnd())
    {
	if(r->isStartElement() && r->name().toString() == "Bookmark")
	{
	    Bookmark * bm = new Bookmark();
	    bm->deserialize(r);
	    this->append(bm);
	}
	r->readNext();
    }
    return true;
}
